/**
 * 
 */
package com.sqq.model.kl;

import java.util.Date;

import com.jfinal.ext.plugin.tablebind.TableBind;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sqq.jfinalbase.SqqModel;
import com.sqq.util.DateUtil;

/**
 *@author gqy
 *2015-1-13
 */

/**
 * 记录xunou客流模块的常量或者持久化的信息
 */
@TableBind(tableName = "kl_parameter")
public class KlParameterModel extends SqqModel<KlParameterModel> {

	/**
	 * 
	 */
	
	public final static String KL_MAC_VISIT_LAST_DATETIME = "Kl_Mac_Visit_Last_Datetime";
	
	public final static String KL_MAC_INFO_LAST_DATETIME = "Kl_Mac_Info_Last_Datetime";
	
	private static final long serialVersionUID = 1L;
	public static KlParameterModel dao = new KlParameterModel();
	
	/**
	 * 根据参数code获取参数值
	 * @param paraCode
	 * @return
	 */
	public static Record findParameterByParaCode(String paraCode){
		return Db.findFirst("select * from kl_parameter where para_name =? ", paraCode);
	}
	
	/**
	 * 获取最后一次客流统计的扫描mac的时间及获取下一次统计的起始时间
	 * @return
	 */
	public static String getKlMacVisitLastDatetime(){
		Record record = findParameterByParaCode(KL_MAC_VISIT_LAST_DATETIME);
		return record.getStr("para_value");
	}
	
	/**
	 * 记录最后一次统计的时间，也就是记录下次统计的起始时间
	 * @param klMacVisitLastDatetime
	 */
	public static void storeKlMacVisitLastDatetime(Date klMacVisitLastDatetime){
		String str = DateUtil.format(klMacVisitLastDatetime);
		Db.update("update kl_parameter set para_value = ? where para_name =? ",str,KL_MAC_VISIT_LAST_DATETIME);
	}
	
	/**
	 * 
	 * @return
	 */
	public static String getKlMacInfoLastDatetime(){
		Record record = findParameterByParaCode(KL_MAC_INFO_LAST_DATETIME);
		return record.getStr("para_value");
	}
}
